#include <cstdio>

int a[100005];

int main()
{
    freopen("in.txt","r",stdin);
    int n,k;
    while ( scanf("%d%d",&n,&k) != EOF )
    {
        int flag=1;
        int cnt=0;
        for (int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        for ( int i=k;i<n;i++ )
        if ( a[k-1] == a[i] )
        {
            flag=1;
        }
        else
        {
            flag=0;
            break;
        }
        if ( flag == 1 )
        {
            for(int i=0;i<k-1;i++)
            {
                if (a[i] !=  a[i+1])
                    cnt=i+1;
            }
            printf("%d\n",cnt);
        }
        else
            printf("-1\n");
    }
    return 0;
}
